package com.leetcode.No2383;

import org.junit.Test;

/**
 * 2383.赢得比赛需要的最少训练时长
 */
public class Solution {
    public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
        int result = 0;

        for (int en : energy) {
            initialEnergy -= en;
        }
        if (initialEnergy <= 0) {
            result = -initialEnergy + 1;
        }

        for (int exp : experience) {
            if (initialExperience <= exp) {
                result += (exp + 1 - initialExperience);
                initialExperience = exp + 1;
            }
            initialExperience += exp;
        }

        return result;
    }

    @Test
    public void test1() {
        int initialEnergy = 5;
        int initialExperience = 3;
        int[] energy = new int[]{1,4,3,2};
        int[] experience = new int[]{2,6,3,1};

        System.out.println(minNumberOfHours(initialEnergy, initialExperience, energy, experience));
    }
}
